package com.springboot.chapter2;

import com.springboot.chapter1.pojo.User;
import com.springboot.chapter2.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class ThymeleafController {
	@GetMapping("/index")
	public String index(Model model){
		List<User>userList=new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			User user=new User();
			user.setUserName("张三");
			user.setPassword("111");
			user.setTelephone("133");
			userList.add(user);
		}
		model.addAttribute("username","admin");
		model.addAttribute("userList",userList);
		model.addAttribute("date",new Date());
		model.addAttribute("salary",2000.168);
		model.addAttribute("word","Hello,World");
		return "/chapter2/index";
	}
	@GetMapping("/students")
	public String getAllStudents(Model model){
		List<Student> students=new ArrayList<>();
		students.add(new Student(1,"张三","女",20,"计科一班"));
		students.add(new Student(2,"李四","男",21,"计科二班"));
		students.add(new Student(3,"李白","男",18,"计科三班"));
		model.addAttribute("students",students);
		return "/chapter2/students";
	}
}
